package com.probox.modules.controller.wechat;

import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.entity.domain.wechat.broadcast.WechatBroadcast;
import com.probox.common.entity.domain.wechat.vo.AddGoodsVo;
import com.probox.common.entity.domain.wechat.vo.QueryRoomVo;
import com.probox.common.entity.domain.wechat.vo.ResponseWechatBroadcastVo;
import com.probox.common.entity.service.wechat.WechatBroadcastService;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Kite
 * @date 2021/7/9
 */
@RestController
@RequestMapping("/wechat/broadcast")
public class WechatBroadcastController extends BaseController {

    @Autowired
    private WechatBroadcastService wechatBroadcastService;


    /**
     * 申请开通直播权限
     */
    @ApiOperation(value = "申请开通直播权限")
    @Log(title = "申请开通直播权限", businessType = BusinessType.GRANT)
    @PostMapping("/applyFor")
    public AjaxResult applyFor() {
        return AjaxResult.success(wechatBroadcastService.applyFor());
    }

    /**
     * 查询是否有权限
     */
    @ApiOperation(value = "查询是否有权限")
    @Log(title = "查询是否有权限", businessType = BusinessType.GRANT)
    @GetMapping("/queryPermissions")
    public AjaxResult queryPermissions() {
        return AjaxResult.success(wechatBroadcastService.queryPermissions());
    }

    /**
     * 创建直播间
     */
    @ApiOperation(value = "创建直播间")
    @Log(title = "创建直播间", businessType = BusinessType.GRANT)
    @PostMapping("/creatRoom")
    public AjaxResult creatRoom(@RequestBody WechatBroadcast wechatBroadcast) {
        return AjaxResult.success(wechatBroadcastService.creatRoom(wechatBroadcast));
    }

    /**
     * 编辑直播间"
     */
    @ApiOperation(value = "编辑直播间")
    @Log(title = "编辑直播间", businessType = BusinessType.GRANT)
    @PostMapping("/updateRoom")
    public AjaxResult updateRoom(@RequestBody WechatBroadcast wechatBroadcast) {
        return AjaxResult.success(wechatBroadcastService.updateRoom(wechatBroadcast));
    }

    /**
     * 直播间导入商品
     */
    @ApiOperation(value = "直播间导入商品")
    @Log(title = "直播间导入商品", businessType = BusinessType.GRANT)
    @PostMapping("/addGoods")
    public AjaxResult addGoods(@RequestBody AddGoodsVo addGoodsVo) {
        return AjaxResult.success(wechatBroadcastService.addGoods(addGoodsVo));
    }

    /**
     * 查询直播间列表
     */
    @ApiOperation(value = "查询直播间列表")
    @Log(title = "查询直播间列表", businessType = BusinessType.GRANT)
    @GetMapping("/getRoomList")
    public AjaxResult getRoomList(QueryRoomVo queryRoomVo) {
        return AjaxResult.success(wechatBroadcastService.getRoomList(queryRoomVo));
    }

    /**
     * 查询数据库直播间列表
     */
    @ApiOperation(value = "查询直播间列表")
    @Log(title = "查询直播间列表", businessType = BusinessType.GRANT)
    @GetMapping("/getList")
    public AjaxResult getList(String name) {
        startPage();
        List<ResponseWechatBroadcastVo> cardContrList = wechatBroadcastService.getList(name);
        return AjaxResult.successs(cardContrList,wechatBroadcastService.getWchatBroadcastTotal(name));
    }


    /**
     * 删除直播间
     */
    @ApiOperation(value = "删除直播间")
    @Log(title = "删除直播间", businessType = BusinessType.GRANT)
    @PostMapping("/deleteRoom/{id}")
    public AjaxResult deleteRoom(@PathVariable("id") Integer id) {
        return AjaxResult.success(wechatBroadcastService.deleteRoom(id));
    }



    /**
     * 上下架商品
     */
    @ApiOperation(value = "上下架商品")
    @Log(title = "上下架商品", businessType = BusinessType.GRANT)
    @PostMapping("/onsale")
    public AjaxResult onsale(@RequestBody QueryRoomVo queryRoomVo) {
        return AjaxResult.success(wechatBroadcastService.onsale(queryRoomVo));
    }


    /**
     * 删除直播间商品
     */
    @ApiOperation(value = "删除直播间商品")
    @Log(title = "删除直播间商品", businessType = BusinessType.GRANT)
    @PostMapping("/deleteRoomGood")
    public AjaxResult deleteRoomGood(@RequestBody QueryRoomVo queryRoomVo) {
        return AjaxResult.success(wechatBroadcastService.deleteRoomGood(queryRoomVo));
    }


    /**
     * 获取直播间二维码
     */
    @ApiOperation(value = "获取直播间二维码")
    @Log(title = "获取直播间二维码", businessType = BusinessType.GRANT)
    @PostMapping("/getShare/{roomId}")
    public AjaxResult getShare(@PathVariable Integer roomId) {
        return AjaxResult.success(wechatBroadcastService.getShare(roomId));
    }

}
